package com.myhealth.hb.measurmentscanner;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.RadioButton;
import android.widget.Toast;

import java.util.Random;


public class HeartBeatGenerator extends Activity {

    private Random generator;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_heart_beat_generator);
        this.generator = new Random();
    }

    public void generateHeartBeatRate(View view){
        // Is the button now checked?
        boolean checked = ((RadioButton) view).isChecked();

        // Check which radio button was clicked
        switch(view.getId()) {
            case R.id.extreme_low:
                if (checked)
                    Toast.makeText(getApplicationContext(),"HeartBeatRate: " + this.genRandomHeartBeat(0,40), Toast.LENGTH_SHORT).show();
                break;
            case R.id.low:
                if (checked)
                    Toast.makeText(getApplicationContext(),"HeartBeatRate: " + this.genRandomHeartBeat(40,60) , Toast.LENGTH_SHORT).show();
                break;
            case R.id.normal:
                if (checked)
                    Toast.makeText(getApplicationContext(),"HeartBeatRate: " + this.genRandomHeartBeat(60,100) , Toast.LENGTH_SHORT).show();
                break;
            case R.id.high:
                if (checked)
                    Toast.makeText(getApplicationContext(), "HeartBeatRate: " + this.genRandomHeartBeat(100, 120), Toast.LENGTH_SHORT).show();
                break;
            case R.id.extreme_high:
                if (checked)
                    Toast.makeText(getApplicationContext(),"HeartBeatRate: " + this.genRandomHeartBeat(120,160) , Toast.LENGTH_SHORT).show();
                break;

        }
    }

    private int genRandomHeartBeat(int min, int max){
        return generator.nextInt(max-min) + min;
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if(id == R.id.action_main){
            Intent mainIntent = new Intent(this, Main.class);
            startActivity(mainIntent);
            return true;
        }
        if(id == R.id.action_heartbeat) {

            return true;
        }
        if (id == R.id.action_bloodpressure) {
            Intent bloodPressureIntent = new Intent(this, BloodPressureGenerator.class);
            startActivity(bloodPressureIntent);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

}
